package cn.zebra.dev.other.module.discountsMember.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.other.module.discountsMember.dao.DiscountsMemberDao;
import cn.zebra.dev.other.module.discountsMember.entity.DiscountsMemberEntity;
import cn.zebra.dev.other.module.discountsMember.service.DiscountsMemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 
 *
 * @author runnable
 */
@Service
public class DiscountsMemberServiceImpl extends ServiceImpl<DiscountsMemberDao, DiscountsMemberEntity> implements DiscountsMemberService {

    @Override
    public PageUtils<DiscountsMemberEntity> findPage(Map<String, Object> params) {
        QueryWrapper<DiscountsMemberEntity> wrapper = new QueryWrapper<>();
        wrapper.apply(params.containsKey("discountsUserId"),"discounts_user_id ={0}",params.get("discountsUserId"));
        IPage<DiscountsMemberEntity> page = this.page(
                new Query<DiscountsMemberEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    @Override
    public Boolean updateDiscountsById(Long id, DiscountsMemberEntity discountsMemberEntity) {
        return update(discountsMemberEntity,"id ={0}",id);
    }
}
